<template>
    <div class="header-container">
      <div class="left">
        <el-menu 
          :default-active="activeIndex" 
          class="fixed-menu" 
          mode="horizontal" 
          :ellipsis="false"
          router
        >
          <router-link class="logo" to="/">健行网</router-link>
          <el-menu-item index="/">健康</el-menu-item>
          <el-sub-menu index="2">
            <template #title>运动</template>
            <el-menu-item index="2-1">户外跑步</el-menu-item>
            <el-menu-item index="2-2">瑜伽</el-menu-item>
            <el-menu-item index="2-3">其他</el-menu-item>
          </el-sub-menu>
          <el-menu-item index="/cart">会员</el-menu-item>
          <el-menu-item index="/detail">设备</el-menu-item>
        </el-menu>
        
   
          
       
      </div>
      <div class="right">
        <div v-if="true">
          <el-button type="primary" class="right-btn" @click="goLogin">登录</el-button>
          <el-button type="primary" class="right-btn">注册</el-button>
        </div>
        <el-sub-menu v-else>
          <template #title>user</template>
          <el-menu-item index="2-1">退出</el-menu-item>
        </el-sub-menu>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from "vue";
  import { useRouter } from "vue-router";
  const router = useRouter()
  let activeIndex = ref("");
  let username = ref("");
  const goLogin = () => {
    router.push({
      path: "/login",
    });
  };
  </script>
  
  <style scoped>
  .header-container {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: fit-content; /* 确保容器不会小于内容宽度 */
  }
  
  .left {
    flex: 1;
    min-width: 0; /* 允许内容收缩 */
  }
  
  .right {
    flex-shrink: 0; /* 防止右侧内容被压缩 */
  }
  
  .fixed-menu {
    display: flex;
    align-items: center;
    height: 60px;
    width: 100%;
    flex-wrap: nowrap;
    overflow: hidden; /* 防止内容溢出 */
  }
  
  .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-width: 120px;
    font-size: 24px;
    color: #161513;
    text-decoration: none;
    white-space: nowrap;
    padding: 0 20px;
  }
  
  .right-btn {
    margin: 0 10px;
    white-space: nowrap;
  }
  
  /* 确保菜单项不会换行 */
  :deep(.el-menu--horizontal > .el-menu-item),
  :deep(.el-menu--horizontal > .el-sub-menu .el-sub-menu__title) {
    white-space: nowrap;
  }
  </style>